let dirname = __dirname.split("config")[0];

const HtmlWebpackPlugin = require("html-webpack-plugin");
let htmlPlugin = new HtmlWebpackPlugin({
    // 打包模板
    template: "./public/index.html",
    // 打包后文件名称
    filename: "index.html"
})

module.exports = {
    // development 开发环境
    mode: "development",
    entry: "./src/index.js",
    output: {
        filename: "build.js",
        path: dirname + "dist"
    },
    module: {
        // 匹配规则
        rules: [
            {
                test: /\.css$/i,
                use: ["style-loader", "css-loader"]
            },
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                type: 'asset/resource',
            },
            // {
            //     test: /\.less$/i,
            //     use: ["style-loader", "css-loader", "less-loader"],
            // },
            // {
            //     test: /\.s[ac]ss$/i,
            //     use: ['style-loader','css-loader','sass-loader',],
            // },
            {
                test: /\.(js|jsx)$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react']
                    }
                }
            }
        ]
    },
    plugins: [
        htmlPlugin,

    ],
    devServer: {
        // 端口号
        port: 9000,
        //服务启动后是否打开默认浏览器
        open: true,
        client: {
            overlay: false
        }
    }

}